import 'package:flutter/material.dart';

/// 应用主题配置，定义全局颜色、字体和样式
class AppTheme {
  // 主色调
  static const Color primaryColor = Color(0xFF4361ee);
  static const Color primaryLight = Color(0xFF7209b7);
  static const Color primaryDark = Color(0xFF3a0ca3);

  // 辅助色
  static const Color secondaryColor = Color(0xFFf72585);
  static const Color secondaryLight = Color(0xFFb5179e);

  // 中性色
  static const Color backgroundColor = Color(0xFFf8f9fa);
  static const Color cardColor = Color(0xFFffffff);
  static const Color surfaceColor = Color(0xFFf5f5f5);
  static const Color textPrimary = Color(0xFF212529);
  static const Color textSecondary = Color(0xFF6c757d);
  static const Color borderColor = Color(0xFFdee2e6);

  // 状态色
  static const Color successColor = Color(0xFF2ecc71);
  static const Color errorColor = Color(0xFFe74c3c);
  static const Color warningColor = Color(0xFFf39c12);
  static const Color infoColor = Color(0xFF3498db);

  // 阴影
  static const BoxShadow cardShadow = BoxShadow(
    color: Color(0x10000000),
    blurRadius: 8,
    spreadRadius: 2,
    offset: Offset(0, 2),
  );

  // 创建主题数据
  static ThemeData get lightTheme {
    return ThemeData(
      // 主颜色配置
      primaryColor: primaryColor,
      primarySwatch: createMaterialColor(primaryColor),

      // 亮度和主题模式
      brightness: Brightness.light,

      // 文本主题
      textTheme: const TextTheme(
        headlineLarge: TextStyle(
            fontSize: 32, fontWeight: FontWeight.bold, color: textPrimary),
        headlineMedium: TextStyle(
            fontSize: 28, fontWeight: FontWeight.bold, color: textPrimary),
        headlineSmall: TextStyle(
            fontSize: 24, fontWeight: FontWeight.bold, color: textPrimary),
        titleLarge: TextStyle(
            fontSize: 20, fontWeight: FontWeight.bold, color: textPrimary),
        bodyLarge: TextStyle(fontSize: 16, color: textPrimary),
        bodyMedium: TextStyle(fontSize: 14, color: textSecondary),
        bodySmall: TextStyle(fontSize: 12, color: textSecondary),
      ),

      // 卡片主题
      cardTheme: CardTheme(
        color: cardColor,
        elevation: 0,
        shadowColor: Colors.transparent,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(12),
          side: const BorderSide(color: borderColor),
        ),
      ),

      // 按钮主题
      elevatedButtonTheme: ElevatedButtonThemeData(
        style: ElevatedButton.styleFrom(
          backgroundColor: primaryColor,
          foregroundColor: Colors.white,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(8),
          ),
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
          textStyle: const TextStyle(fontWeight: FontWeight.bold),
        ),
      ),

      // 输入框主题
      inputDecorationTheme: InputDecorationTheme(
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(8),
          borderSide: const BorderSide(color: borderColor),
        ),
        enabledBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(8),
          borderSide: const BorderSide(color: borderColor),
        ),
        focusedBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(8),
          borderSide: const BorderSide(color: primaryColor, width: 2),
        ),
        errorBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(8),
          borderSide: const BorderSide(color: errorColor),
        ),
        filled: true,
        fillColor: surfaceColor,
        contentPadding:
            const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
      ),

      // 应用栏主题
      appBarTheme: const AppBarTheme(
        backgroundColor: primaryColor,
        foregroundColor: Colors.white,
        elevation: 4,
        centerTitle: true,
        titleTextStyle: TextStyle(
          fontSize: 18,
          fontWeight: FontWeight.bold,
        ),
      ),

      // 底部导航栏主题
      bottomNavigationBarTheme: BottomNavigationBarThemeData(
        backgroundColor: Colors.white,
        selectedItemColor: primaryColor,
        unselectedItemColor: textSecondary,
        selectedLabelStyle: const TextStyle(fontWeight: FontWeight.bold),
        elevation: 8,
      ),

      // 图标主题
      iconTheme: const IconThemeData(color: textPrimary),
      primaryIconTheme: const IconThemeData(color: Colors.white),

      // 分隔线主题
      dividerTheme: const DividerThemeData(
        color: borderColor,
        thickness: 1,
        indent: 16,
        endIndent: 16,
      ),

      // 其他
      scaffoldBackgroundColor: backgroundColor,
      colorScheme: ColorScheme.fromSwatch().copyWith(
        primary: primaryColor,
        secondary: secondaryColor,
        background: backgroundColor,
        surface: surfaceColor,
        error: errorColor,
        onPrimary: Colors.white,
        onSecondary: Colors.white,
        onBackground: textPrimary,
        onSurface: textPrimary,
        onError: Colors.white,
      ),
    );
  }

  // 将Color转换为MaterialColor（用于primarySwatch）
  static MaterialColor createMaterialColor(Color color) {
    // 简化实现，只提供必要的颜色映射
    return MaterialColor(color.value, {
      500: color,
      100: color,
      200: color,
      300: color,
      400: color,
      600: color,
      700: color,
      800: color,
      900: color,
      50: color,
    });
  }
}
